import os

import xarray as xr

from ppgnss import gnss_utils

obj_dir = "../data/snr"
out_dir = "../data/snr"
sites = ["B216", "B240", "B286", "PD02"]
doys = [98, 99, 100, 101, 102, 103, 104]
for site in sites:
    for idoy, doy in enumerate(doys):
        obj_filename = os.path.join(obj_dir, "%s%03d.obj" % (site, doy))
        data = gnss_utils.loadobject(obj_filename)
        xr_ele_doy, xr_azi_doy, xr_snr_doy = data["ele"], data["azi"], data["snr"]
        if idoy == 0:
            xr_ele, xr_azi, xr_snr = xr_ele_doy, xr_azi_doy, xr_snr_doy
        else:
            xr_ele = xr.concat([xr_ele, xr_ele_doy], dim="time")
            xr_azi = xr.concat([xr_azi, xr_azi_doy], dim="time")
            xr_snr = xr.concat([xr_snr, xr_snr_doy], dim="time")
    data = {"ele": xr_ele,
            "azi": xr_azi,
            "snr": xr_snr}
    outfile = os.path.join(out_dir, "%s.obj"%site)
    gnss_utils.saveobject(data, outfile)
    print(outfile + " is saved!")